package com.gla.giliair.service.impl;

import com.gla.giliair.dao.CabinInfoDao;
import com.gla.giliair.entity.*;
import com.gla.giliair.service.CabinInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Description:
 * @Author: Yingtian qian
 * @Date: 2021/8/24 17:23
 */
@Service
public class CabinInfoServiceImpl implements CabinInfoService {
    @Autowired
    private CabinInfoDao cabinInfoDao;

    @Override
    public CabinInfo selectCabinInfoById(Long cabinInfoId) {
        if (cabinInfoId != null) {
            CabinInfoExample cabinInfoExample = new CabinInfoExample();
            cabinInfoExample.or().andCabinInfoIdEqualTo(cabinInfoId).andIsDeletedEqualTo(0);
            List<CabinInfo> cabinInfoList = cabinInfoDao.selectByExample(cabinInfoExample);
            if (cabinInfoList.isEmpty()) {
                return null;
            }
            return cabinInfoList.get(0);
        }
        return null;
    }

    @Override
    public CabinInfo selectCabinInfoByFlightId(Long flightId) {
        if (flightId != null) {
            CabinInfoExample cabinInfoExample = new CabinInfoExample();
            cabinInfoExample.or().andFlightIdEqualTo(flightId).andIsDeletedEqualTo(0);
            List<CabinInfo> cabinInfoList = cabinInfoDao.selectByExample(cabinInfoExample);
            if (cabinInfoList.isEmpty()) {
                return null;
            }
            return cabinInfoList.get(0);
        }
        return null;
    }
}
